const treeData = require("./treeData");
const { clone } = require("../cloneDeep");
/**
 *
 * @param { any[] } treeData
 */
function getPathNodes(treeData, id, result = []) {
  function depth(treeData, id, result) {
    const it = treeData.find((item) => {
      if (item.id === id) {
        return true;
      }
      if (item.children && item.children.length) {
        const node = depth(item.children, id, result);
        if (node) {
          return true;
        }
      }
    });
    if (it) {
      result.unshift(it.name);
    }
    return it;
  }
  depth(treeData, id, result);
  return result;
}
console.log(getPathNodes(treeData, 13));
